home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_10.lha
/
6_10
/
6_10tst.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
128 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <stream.h>
include <values.h>
include "lint.h"
nsigned long iarray[] =
{
0,
1,
/ 2,
/ 3,
/ 4,
/ 5,
/ 6,
/ 17,
/ 1234,
/ 0x1234,
/ 12345,
0x12345,
/ 12345678,
0x12345678,
MAXINT,
0xFFFFFFFF
};
onst int sziarray = sizeof(iarray)/sizeof(iarray[0]);
INT Parray[sziarray*sziarray], Narray[sziarray*sziarray];
nt szarray = 0;
oid init()
for (int i = 0; i < sziarray; i++)
for (int j = 0; j < sziarray; j++)
Parray[szarray++] = LINT(iarray[i], iarray[j]);
for (i = 0; i < szarray; i++)
Narray[i] = -Parray[i];
oid testdiv(LINT *A, LINT *B)
for (int i = 0; i < szarray; i++)
for (int j = 1; j < szarray; j++)
{
LINT quot, rem;
dodivmod(A[i], B[j], quot, rem);
cout << A[i] << " / " << B[j] << " = " << quot << "\n";
cout << A[i] << " % " << B[j] << " = " << rem << "\n";
}
oid testmul(LINT *A, LINT *B)
for (int i = 0; i < szarray; i++)
for (int j = 0; j < szarray; j++)
{
LINT prod = A[i] * B[j];
cout << A[i] << " * " << B[j] << " = " << prod << "\n";
}
oid testadd(LINT *A, LINT *B)
for (int i = 0; i < szarray; i++)
for (int j = 0; j < szarray; j++)
{
LINT sum = A[i] + B[j];
cout << A[i] << " + " << B[j] << " = " << sum << "\n";
}
oid testsub(LINT *A, LINT *B)
for (int i = 0; i < szarray; i++)
for (int j = 0; j < szarray; j++)
{
LINT diff = A[i] - B[j];
cout << A[i] << " - " << B[j] << " = " << diff << "\n";
}
oid testneg(LINT *A)
for (int i = 0; i < szarray; i++)
{
LINT neg = -A[i];
cout << " - " << A[i] << " = " << neg << "\n";
}
oid testpos(LINT *A)
for (int i = 0; i < szarray; i++)
{
LINT pos = +A[i];
cout << " 0 + " << A[i] << " = " << pos << "\n";
}
oid testsuite(LINT *A, LINT *B)
testadd(A, B);
testsub(A, B);
testmul(A, B);
testdiv(A, B);
testneg(A);
testpos(A);
ain(int, char **)
init();
/ for (int i = 0; i < szarray; i++)
/ cerr << "Parray[" << i << "]=" << Parray[i] << "\n";
/ for (i = 0; i < szarray; i++)
/ cerr << "Narray[" << i << "]=" << Narray[i] << "\n";
testsuite(Parray, Parray);
/ testsuite(Parray, Narray);
/ testsuite(Narray, Parray);
/ testsuite(Narray, Narray);
return 0;